package cn.wen233.core.page;

import lombok.Data;

import java.util.List;

/**
 * 分页数据
 *
 * @author wenjie
 * @date 2022-03-24 15:51
 */
@Data
public class PageOut<T> {

    private Long pageSize;

    private Long pageNumber;

    private Long totalNumber;

    private Long totalSize;

    private List<T> data;

    public PageOut(Long pageSize, Long pageNumber, Long totalNumber, Long totalSize, List<T> data) {
        this.pageSize = pageSize;
        this.pageNumber = pageNumber;
        this.totalNumber = totalNumber;
        this.totalSize = totalSize;
        this.data = data;
    }

    public PageOut(List<T> data, Long totalSize, Long pageSize, Long pageNumber) {
        this(pageSize, pageNumber, Math.round(Math.ceil(totalSize * 1.0 / pageSize)), totalSize, data);
    }

    public static <T> PageOut<T> of(List<T> data, Long totalSize, Long pageSize, Long pageNumber) {
        return new PageOut<>(data, totalSize, pageSize, pageNumber);
    }

    public static <T> PageOut<T> of(List<T> data, Integer totalSize, Integer pageSize, Integer pageNumber) {
        return new PageOut<T>(data, totalSize.longValue(), pageSize.longValue(), pageNumber.longValue());
    }
}
